package org.xm.sk.dao;

import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.xm.sk.vo.tb.Activity;

@Repository
public interface ActivityRepository extends JpaRepository<Activity, Integer>,
        JpaSpecificationExecutor<Activity>,
        QuerydslPredicateExecutor<Activity> {

    Set<Activity> findByName(String name);

    @Modifying
    @Query("UPDATE FROM Activity u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id = :id")
    void delete(@Param("id") int id, @Param("userid") int userid,
            @Param("username") String username);

    @Modifying
    @Query("UPDATE FROM Activity u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id in :ids")
    void delete(@Param("ids") Set<Integer> ids, @Param("userid") int userid,
            @Param("username") String username);
}
